home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / SourceCode / OOP_Course / Labs / Stack / Solution / stackMain.m < prev   
Text File  |  1992-12-19  |  2KB  |  59 lines

  1.  
  2. // Main program for testing the Stack object 
  3.  
  4. #import <stdio.h>
  5. #import "Stack.h"
  6.  
  7. main ( argc, argv )
  8. int argc;
  9. char *argv[];
  10. {
  11.     id stack;
  12.     
  13.     printf ("\nCreate a Stack instance...\n");
  14.         stack = [[Stack alloc] init];                //allocate and initialize
  15.  
  16.     printf("Print the stack...\n");    
  17.         [stack printStack];                //print it out
  18.  
  19.     printf ("Push 5.0, 10.0, then 15.0 ...\n");    //push 3 nos.
  20.         [stack  push:5.0];
  21.         [stack  push:10.0];
  22.         [stack  push:15.0];
  23.     
  24.     printf("Print the stack...\n");    
  25.         [stack printStack];
  26.         
  27.     printf("Top of stack is:  %f\n", [stack top]);         //show top of stack
  28.     
  29.     printf("Pop four times...\n");        //illustrate LIFO
  30.         printf("Number popped:  %f\n", [stack pop]);
  31.         printf("Number popped:  %f\n", [stack pop]);
  32.         printf("Number popped:  %f\n", [stack pop]);
  33.         printf("Number popped:  %f\n", [stack pop]);   //empty stack will return 0.0
  34.  
  35.     printf("Print the stack...\n");            //show an empty stack
  36.         [stack printStack];
  37.         
  38.     printf("Fill the stack again with 2.0, 4.0, 6.0, then 8.0...\n");    //refill
  39.         [stack  push:2.0];
  40.         [stack  push:4.0];
  41.         [stack  push:6.0];
  42.         [stack  push:8.0];
  43.     
  44.     printf("Print the stack...\n");            //show 4 numbers
  45.         [stack printStack];
  46.         
  47.     printf("Top of stack is:  %f\n", [stack top]);         //show top of stack
  48.     
  49.     printf("Now empty the stack...\n");            //now empty it
  50.         [stack empty];
  51.     
  52.     printf("Print the stack...\n");            //show an empty stack
  53.         [stack printStack];
  54.  
  55.     printf("Now freeing the stack...\n");        //free it up
  56.         [stack  free];
  57.     
  58. } // end of program
  59.